package sit.engreal.leetcode.problems900;

import sit.engreal.leetcode.util.ListNode;

/**
 * <a href="https://leetcode.cn/problems/middle-of-the-linked-list/">876. 链表的中间结点</a>
 */
public class LeetCode876 {
    public ListNode middleNode(ListNode head) {
        ListNode p = head;
        ListNode q = head.next;

        while (q != null && q.next != null) {
            p = p.next;
            q = q.next.next;
        }
        return q == null ? p : p.next;
    }
}
